package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;


    @Override
    public List<Customer> selectList(Integer page, Integer rows, String customerName) {
        page = (page-1)*rows;
        return customerDao.selectList(page,rows,customerName);
    }

    @Override
    public Boolean saveOrUpdate(Customer customer, String customerId) {
        if (!StringUtils.isEmpty(customerId)){
            customer.setCustomerId(Integer.parseInt(customerId));
            return customerDao.update(customer);
        }else {
            return customerDao.save(customer);
        }
    }

    @Override
    public Boolean delete(String ids) {
        String[] array = ids.split(",");
        Boolean flag = customerDao.delete(array);
        return flag;
    }
}
